<!DOCTYPE html>
<html>
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">
    <title>websocket</title>
</head>
<body>
<div id="msg"></div>
<script type="text/javascript">
     var msg=document.getElementById('msg');
     var url='ws://localhost:1234/html5/WebSockets/a.php';
        if(window.WebSocket){
            var w=new WebSocket(url);
            addmsg('init...');
        }else{
           var w=new MozWebSocket(url);
             addmsg('init...');
        }

        w.onopen=function(e){
            addmsg('open');
            w.send('abc');
        }
        w.onmessage=function(e){
            addmsg(e.data);
        }

        w.onclose=function(e){
            addmsg('close');
        }
        w.onerror=function(e){
            addmsg('error');
        }

    function addmsg(s){
        var p=document.createElement('p');
        p.innerHTML=s;
        msg.appendChild(p);
    }
</script> 

</body>
</html>